﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using EmoneyWeiXinCommon;
using System.Data;

namespace EmoneyWeiXinDAL
{
    public class WeiQunTwoCodeDAL
    {
        public static void Insert(string QunName, string twoCodeUrl)
        {
            string sql = "INSERT INTO WeiQunTwoCode(QunName,twoCodeUrl,UpdateTime,Statu) VALUES(@QunName,@twoCodeUrl,GetDate(),0)";
            SqlParameter[] paras = 
            {
              new SqlParameter("@QunName",QunName),
              new SqlParameter("@twoCodeUrl",twoCodeUrl)
            };

            SQLHelper.ExecuteNonQuery(Config.EmoneyWeiXin, System.Data.CommandType.Text, sql, paras);
        }

        //获取列表
        public static DataTable GetList()
        {
            string sql = "SELECT * FROM WeiQunTwoCode with(nolock)";
            return SQLHelper.ExecuteGetTable(Config.EmoneyWeiXin, System.Data.CommandType.Text, sql, null);
        }

        public static void SetToUsing(string id)
        {
            string sql = "UPDATE WeiQunTwoCode SET Statu=1 WHERE ID=@Id;  UPDATE WeiQunTwoCode SET Statu=0 WHERE ID<>@Id; ";
            SqlParameter[] paras = 
            {
              new SqlParameter("@Id",id)
            };
            SQLHelper.ExecuteNonQuery(Config.EmoneyWeiXin, System.Data.CommandType.Text, sql, paras);
        }

        public static void Delete(string id)
        {
            string sql = "DELETE WeiQunTwoCode WHERE ID=@Id";
            SqlParameter[] paras = 
            {
              new SqlParameter("@Id",id)
            };
            SQLHelper.ExecuteNonQuery(Config.EmoneyWeiXin, System.Data.CommandType.Text, sql, paras);
        }
        //获取正在使用的
        public static string GetUsing()
        {
            string sql = "SELECT top 1 twoCodeUrl FROM WeiQunTwoCode where statu=1";
            object o = SQLHelper.ExecuteScalar(Config.EmoneyWeiXin, System.Data.CommandType.Text, sql, null);
            return o.ToString();
        }
    }
}
